<template>
  <div class="headForm">
    <div class="left-view">
      <div class="phone-header">
        <div class="title">{{ list[leftIndex].formName }}</div>
      </div>
      <div class="content-header">
        <img :src="list[leftIndex].imageUrl" alt >
        <div class="form">
          <div class="title">{{ list[leftIndex].formName }}</div>
          <div class="content">{{ list[leftIndex].formContent }}</div>
        </div>
      </div>
    </div>
    <div v-if="list[leftIndex].showRight" class="right-view">
      <div class="form-title">
        表单名称
        <span class="sign">*</span>
      </div>
      <el-input v-model="list[leftIndex].formName" />
      <div class="form-title">
        描述内容
        <span class="sign">*</span>
      </div>
      <el-input v-model="list[leftIndex].formContent" />
      <div class="form-title">背景图</div>
      <div class="uplode-box">
        <el-upload
          :show-file-list="false"
          :on-success="handleBgImgSuccess"
          :before-upload="beforeBgImgUpload"
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
        >
          <img v-if="list[leftIndex].imageUrl" :src="list[leftIndex].imageUrl" class="avatar" >
          <i v-else class="el-icon-plus avatar-uploader-icon" />
        </el-upload>
        <div class="hint">建议尺寸：750*320px，小于5M，支持jpg、png、jpeg格式</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ['list', 'leftIndex'],
  data() {
    return {

    }
  },
  methods: {
    handleBgImgSuccess(res, file) {
      this.list[this.leftIndex].imageUrl = URL.createObjectURL(file.raw)
    },
    beforeBgImgUpload(file) {
      const isJPG = file.type === 'image/jpeg' || 'image/png'
      const isLt5M = file.size / 1024 / 1024 < 5

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt5M) {
        this.$message.error('上传头像图片大小不能超过 5MB!')
      }
      return isJPG && isLt5M
    }
  }
}
</script>

<style lang="scss" scoped>
.headForm {
  .left-view {
    .phone-header {
      width: 371px;
      height: 65px;
      padding-top: 30px;
      background: url(/src/assets/analyze_data/phone_header.png);
      -webkit-background-size: contain;
      background-size: contain;
      .title {
        width: 100%;
        height: 28px;
        padding: 0 40px;
        overflow: hidden;
        font-weight: bold;
        line-height: 28px;
        white-space: nowrap;
        text-align: center;
        text-overflow: ellipsis;
        font-size: 20px;
        color: #353535;
      }
    }
    .content-header {
      position: relative;
      width: 371px;
      height: 160px;
      img {
        width: 100%;
        height: 100%;
      }
      .form {
        position: absolute;
        top: 0;
        left: 0;
        z-index: 100;
        width: 100%;
        height: 100%;
        text-align: center;
        background-color: rgba(0, 0, 0, 0.6);
        color: #fff;
        .title {
          width: 100%;
          height: 28px;
          margin-top: 50px;
          padding: 0 20px;
          overflow: hidden;
          line-height: 28px;
          white-space: nowrap;
          -o-text-overflow: ellipsis;
          text-overflow: ellipsis;
        }
        .content {
          width: 258px;
          height: 34px;
          margin: 16px 58px 0;
          overflow: hidden;
          line-height: 17px;
          opacity: 0.7;
        }
      }
    }
  }
  .right-view {
    position: absolute;
    top: 0;
    left: 100%;
    z-index: 7;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 355px;
    min-height: 28px;
    margin-left: 20px;
    padding: 0 20px 20px;
    color: #353535;
    font-size: 14px;
    font-family: 'PingFangSC-Medium';
    background: #f8f8f8;
    border: 1px solid #e5e5e5;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    .form-title {
      margin: 16px 0px;
      .sign {
        color: red;
      }
    }
  }
  .right-view::before {
    border-color: transparent;
    border-right-color: #e5e5e5;
    position: absolute;
    top: 40px;
    left: -20px;
    content: ' ';
    width: 0px;
    height: 0px;
    border-width: 10px;
    border-style: solid;
  }

  .uplode-box {
    display: flex;
    align-items: center;
    .avatar-uploader {
      .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
      }
      .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 100px;
        height: 70px;
        line-height: 70px;
        text-align: center;
      }
      .avatar {
        width: 100px;
        height: 70px;
        display: block;
      }
    }
    .hint {
      height: 34px;
      line-height: 17px;
      font-size: 12px;
      color: #888;
      margin-left: 20px;
    }
  }
}
</style>
